<?php
  ob_start();
  session_start();
  include('header.php');
  include_once(constant('PATH_INCLUDE').'/class.validatecode.php');
  $action= isset($_REQUEST["action"])?$_REQUEST["action"]:'';
switch($action)
{
	case 'save':
		if(!ValidateCode::isContactCodeCorrect($_REQUEST['validatecode']))
		{
			$errorMessage = "驗證碼不正確";
		}else{
		$dt = new DataTable(constant('DB_TABLE_CONTACT_INFO'));
		unset($_REQUEST['id']);
		$dt->save($_REQUEST);
		}
	break;
}
  ?>
  <script language="javascript">
  function submit_form_act()
  {
  if(checkform(document.forms[0]))
  {
  	document.forms[0].submit();
  }
  return false;
  }
  function clear_form_act()
  {
  document.forms[0].reset();
  return false;
  }
  
<?php if($errorMessage):?>
		alert('<?php echo $errorMessage;?>');
<?php elseif($action == 'save'):?>
<?php
	unset($_REQUEST['textfield']);
	for($i=2;$i<10;$i++)
	{
		unset($_REQUEST['textfield'.$i]);
	}
?>
alert('發送成功');
<?php endif;?>

function checkform(form)
{
var str = form.textfield5.value;
//var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
var reg = /^(.+)@(.+)$/;
if(!reg.test(str))
{
	alert('E-mail 格式不正確，請重新輸入');
	form.textfield5.focus();
	return false;
}
return true;
}
  </script>
  <style>
  input
  {
  	width:300px;
  }
  </style>
 <div id="maincontent">
    <div><img src="images/contacttitle.jpg" /></div>
    <div id="listmain">
      <div id="listtop1"></div>
      
      <div id="listmain"><div class="xiangxi">
          <div style="float:left; width:530px;">
           <?php echo Util::htmlStrAfterReadfromDb(Util::getGlobalValue('CONTACT_US_TEXT1'));?>
            
          
            <div class=" contact" >
              <form method="post">
              <input type="hidden" name="action" value="save"/>
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
                <tr>
                  <td width="90" align="right">姓名：</td>
                  <td colspan="2"><input type="text" name="textfield" id="textfield" value="<?php echo $_REQUEST['textfield'];?>"/></td>
                </tr>
                <tr>
                  <td width="90" align="right">所在地區：</td>
                  <td colspan="2"><input type="text" name="textfield2" id="textfield2" value="<?php echo $_REQUEST['textfield2'];?>"/></td>
                </tr>
                <tr>
                  <td width="90" align="right">地址：</td>
                  <td colspan="2"><input type="text" name="textfield3" id="textfield3" value="<?php echo $_REQUEST['textfield3'];?>"/></td>
                </tr>
                <tr>
                  <td width="90" align="right">郵遞區號：</td>
                  <td colspan="2"><input type="text" name="textfield4" id="textfield4" value="<?php echo $_REQUEST['textfield4'];?>"/></td>
                </tr>
                <tr>
                  <td width="90" align="right">E-mail：</td>
                  <td colspan="2"><input type="text" name="textfield5" id="textfield5" value="<?php echo $_REQUEST['textfield5'];?>"/></td>
                </tr>
                <tr>
                  <td width="90" align="right">行動電話：</td>
                  <td colspan="2"><input type="text" name="textfield6" id="textfield6" value="<?php echo $_REQUEST['textfield6'];?>"/></td>
                </tr>
                <tr>
                  <td width="90" align="right">電話：</td>
                  <td colspan="2"><input type="text" name="textfield7" id="textfield7" value="<?php echo $_REQUEST['textfield7'];?>"/></td>
                </tr>
                <tr>
                  <td width="90" align="right">傳真：</td>
                  <td colspan="2"><input type="text" name="textfield8" id="textfield8" value="<?php echo $_REQUEST['textfield8'];?>"/></td>
                </tr>
                <tr>
                  <td width="90" align="right" valign="top">詢問的問題：</td>
                  <td colspan="2"><textarea name="textfield9" id="textarea" cols="45" rows="5"><?php echo $_REQUEST['textfield9'];?></textarea></td>
                </tr>
                 <tr>
                  <td width="90" align="right">驗 證 碼：</td>
                  <td colspan="2"><input type="text" name="validatecode" id="textfield8" />&nbsp;&nbsp;<img src="validatecode.php"/></td>
                </tr>
                
                <tr>
                  <td height="50" align="right" valign="top">&nbsp;</td>
                  <td width="183" height="50" align="center" valign="bottom"><a href="#" onclick="return submit_form_act();"><img src="images/send.jpg" width="120" height="36" /></a></td>
                  <td width="221" height="50" valign="bottom"><a href="#" onclick="return clear_form_act();"><img src="images/clear.jpg" width="118" height="35" /></a></td>
                </tr>
              </table>
              </form>
            </div>
          </div>
            <div class="img3" style="margin-top:150px;"><img src="images/contactbg.jpg" /></div>
            
      
      </div>

<?php include('bottom.php');?>